package dao;

import common.StuMidClass;
import service.FlushCourse;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class AddClass {
    private static Connection conn=DataBaseConnect.getConn();
    private static String sql="INSERT INTO student_course (studentid,courseid) VALUES(?,?)";
    private static PreparedStatement pstmt;
    static {
        try {
            pstmt=conn.prepareStatement(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    public static boolean addClass(String studentid,String courseid){
        try {
            pstmt.setString(1,studentid);
            pstmt.setString(2,courseid);
            int count=pstmt.executeUpdate();
            if(count==1){
                System.out.println("学生课程中间表插入成功");
                return true;
            }
        } catch (SQLException e) {
            System.out.println("添加课程失败");
            e.printStackTrace();
            return false;
        }
        System.out.println("学生课程中间表插入失败");
        return false;
    }
}
